<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>推送</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui2/aui.css" />
    <style>
        body {
            background-color: #fff;
        }
        .input-wrap{
            padding:0.5rem;
            margin:1rem;
            border:1px solid #ccc;
        }
        .title{
            border:none;
            font-size:28px;
            font-weight: bold;
            text-align: center;
        }
        .buttons{
           margin-top:12px;
           height:50px;
           display: -webkit-flex;
        }
        .buttons>div{
           -webkit-flex:1;
           padding: 0.75rem;
        }
    </style>
</head>
<body>
    <section class="aui-content-padded">
        <div class="aui-card-list">
            <div id="title" class="input-wrap title"></div>
            <div class="input-wrap">
                <input id="name" type="text" placeholder="推荐名称">
            </div>
            <div class="input-wrap">
                <textarea id="detail" placeholder="推荐说明"></textarea>
            </div>
        </div>
    </section>
    <div class="aui-content aui-margin-b-15">
        <ul id="pushlist" class="aui-list aui-list-in">
        </ul>
        <script id="li_temp" type="text/x-dot-template">
            {{for(var i=0;i<it.length;i++){ }}
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    {{=it[i]}}
                </div>
            </li>
            {{ } }}
        </script>
    </div>
    <div class="buttons">
        <div>
            <div tapmode class="aui-btn aui-btn-success aui-btn-block" onclick="push();">推送</div>
        </div>
        <div>
            <div tapmode class="aui-btn aui-btn-success aui-btn-block" onclick="choose();">选择分组</div>
        </div>
    </div>
</body>
<script src="../../script/doT.min.js"></script>
<script data-main="../../script/main" src="../../script/require.js"></script>
<script type="text/javascript">
    var push_ids;
    var token;
    apiready = function(){
        require(["zepto","common"],function(){
            $("#title").html(api.pageParam.data.course.name);
            $zb.prefs.getPrefs('token',function(ret){
                token = ret.value;
            })
        })
    };
    
    function choose(){
        api.execScript({
            name:'pushcourse_win',
            script: 'openframe();'
        });
    }
    
    function showlist(ids,names){
        $("#pushlist").html(doT.template($("#li_temp").text())(names));
        push_ids = ids;
        api.execScript({
	        script: 'closeWin();'
        });
    }
    
    function push(){
        var c_list = [];
        c_list.push(api.pageParam.data.course.id);
        var s_data = {
            values:{
                token:token,
                title:$("#name").val(),
                content:$("#detail").val(),
                course_list:JSON.stringify(c_list),
                push_list:JSON.stringify(push_ids)
            }
        }
        $zb.requestForData(s_data,'push','pushCourses',function(ret){
            if(ret.status=="OK"){
                api.toast({
	                msg:'推送成功'
                });
                api.execScript({
	                script: 'closeWin();'
                });
            }
        })
    }
</script>
</html>